﻿namespace RandomTest
{
    internal class Program
    {/// <summary>
    /// 随机提示按键小游戏
    /// </summary>
    /// <param name="args"></param>
        static void Main(string[] args)
        {
            //定义所耗时间
            double reactionTime = 0;
            //用户输入测试次数
            Console.WriteLine("请输入测试次数");
            string input = Console.ReadLine();
            int round = int.Parse(input);
            //错误次数
            int countOfError = 0;
            //设置随机数
            Random rnd = new Random();
            for (int i = 1; i <= round; i++)
            {
                //定义起始时间
                DateTime beginTime = DateTime.Now;
                Console.Clear();
                Console.WriteLine($"现在正在进行第{i}次测试");
                //随机显示a-z或者A-Z的一个字母
                int rd = rnd.Next(0, 52);
                int theASCII;
                if (rd < 26)
                    theASCII = rd + 65;
                else
                    theASCII = rd + 97 - 26;
                char myLetter = (char)theASCII;
                Console.WriteLine(myLetter);
                bool flag = true;
                //用户根据提示输入相应字母
                do
                {
                    char theInput = Console.ReadKey().KeyChar;
                    if (theInput == myLetter)
                        break;
                    else
                        countOfError++;
                } while (flag == true);
                //定义结束时间
                DateTime endTime = DateTime.Now;
                TimeSpan timeSpan = endTime - beginTime;
                reactionTime += timeSpan.TotalSeconds;
                Console.WriteLine($"总耗时{reactionTime}秒，共出现{countOfError}次错误");
            }
        }
    }
}